#pragma once
// ibTabCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "JA2IniEditor.h"
#include "ibTabCtrl.h"


// CibTabCtrl

IMPLEMENT_DYNAMIC(CibTabCtrl, CTabCtrl)
CibTabCtrl::CibTabCtrl()
{
	m_iCurSel = -1;
	moved = false;
}

CibTabCtrl::~CibTabCtrl()
{
}


BEGIN_MESSAGE_MAP(CibTabCtrl, CTabCtrl)
	ON_NOTIFY_REFLECT(NM_CLICK, OnNMClick)
	ON_WM_MOVE()
	ON_WM_SIZING()
END_MESSAGE_MAP()



// CibTabCtrl message handlers
void CibTabCtrl::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: Add your control notification handler code here
	int iTab;
	int iPaneCount=0;
	CRect r;
	iTab=GetCurSel();
	CDialog *p;
	m_iCurSel=iTab;
	while(iPaneCount<TabPanes.GetCount())
	{
		p = TabPanes.GetAt(iPaneCount); 
		p->ShowWindow(SW_HIDE);
		iPaneCount++;
	}
	
	p = TabPanes.GetAt(m_iCurSel);
	p->ShowWindow(SW_SHOW);
	*pResult = 0;
}


void CibTabCtrl::AddTabPane(CString strCaption,CDialog * pDlg)
{
	TabCaptions.Add(strCaption); 
	TabPanes.Add(pDlg); 
	TC_ITEM tci;
	tci.mask = TCIF_TEXT;
	tci.pszText = (LPSTR)(LPCTSTR)strCaption;
	tci.cchTextMax = strCaption.GetLength();
	InsertItem((TabCaptions.GetCount()-1),&tci);

	CRect r;
	GetWindowRect(r);
	pDlg->SetWindowPos(&CWnd::wndBottom,1,21,r.Width()-2,r.Height()-22,SWP_HIDEWINDOW);
}

void CibTabCtrl::SetDefaultPane(int iPaneIndex)
{
	CDialog *p;
	CRect r;
	m_iCurSel = 0;
	if(iPaneIndex<TabPanes.GetCount())
	{
		SetCurSel(iPaneIndex);
		p = TabPanes.GetAt(iPaneIndex);
		GetWindowRect(r);
		p->SetWindowPos(&CWnd::wndBottom,1,21,r.Width()-2,r.Height()-22,SWP_HIDEWINDOW);
		p->ShowWindow(SW_SHOW); 
	}
}

// CibTabCtrl message handlers

CDialog* CibTabCtrl::OnFileExport()
{
	// TODO: Add your command handler code here
	CDialog *p;
	p = TabPanes.GetAt(m_iCurSel);
	return p;
}
